package com.gxa.modules.community.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.community.entity.*;
import com.gxa.modules.community.service.ParkingFeeService;
import com.gxa.modules.community.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "停车缴费管理")
public class ParkingFeeController {
    @Autowired
    private ParkingFeeService parkingFeeService;
    @ApiOperation("停车缴费管理 查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "username",value ="车主名字",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "statePay",value ="缴费状态 0：未缴费 1：已缴费",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "communityId",value ="小区id",dataType ="int"),
    }
    )
    @GetMapping("/carFee/list")
    public Result<List<ParkingCarFee>> listqueryByPage(@RequestParam @ApiIgnore Map<String,Object> params){
        Result<List<ParkingCarFee>> r=Result.success();
        String page1=(String) params.get("page");
        String limit1=(String)params.get("limit");
        Integer page=Integer.valueOf(page1);
        Integer limit=Integer.valueOf(limit1);
        try {
            PageHelper.startPage(page,limit);
            List<ParkingCarFee> parkingCarFees = this.parkingFeeService.queryByPage(params);
            PageInfo<ParkingCarFee> pageInfo = new PageInfo<>(parkingCarFees);
            long total = (int) pageInfo.getTotal();
            r=Result.success(parkingCarFees,total);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 区域下拉列表查询")
    @GetMapping("/carFee/carPark/list")
    public Result<List<IdPark>> queryCarPark(){
        Result<List<IdPark>> r=Result.success();
        try {
            List<IdPark> idParks = this.parkingFeeService.queryCarPark();
            r=Result.success(idParks);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 车位名称下拉列表查询")
    @GetMapping("/carFee/carRegion/list")
    public Result<List<ParkingName>> carRegion(){
        Result<List<ParkingName>> r=Result.success();
        try {
            List<ParkingName> parkingNames = this.parkingFeeService.carRegion();
            r=Result.success(parkingNames);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 支付方式下拉列表查询")
    @GetMapping("/carFee/payState/list")
    public Result<List<PayStyle>> payState(){
        Result<List<PayStyle>> r=Result.success();
        try {
            List<PayStyle> payState = this.parkingFeeService.payState();
            r=Result.success(payState);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 添加")
    @PostMapping("/carFee/add")
    public Result<List<ParkingCarFeeAU>> carFeeAdd(@RequestBody ParkingCarFeeAU parkingCarFeeAU){

        System.out.println(parkingCarFeeAU);
        Result<List<ParkingCarFeeAU>> r=Result.success();
        try {
            this.parkingFeeService.carFeeAdd(parkingCarFeeAU);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 修改")
    @PutMapping("/carFee/update")
    public Result<List<ParkingCarFeeAU>> carFeeUpdate(@RequestBody ParkingCarFeeAU parkingCarFeeAU){
        System.out.println(parkingCarFeeAU);
        Result<List<ParkingCarFeeAU>> r=Result.success();
        try {
            this.parkingFeeService.carFeeUpdate(parkingCarFeeAU);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 传入id支付状态的修改")
    @PutMapping("/carFee/payState/update")
    public Result<List<ParkingCarFeeAU>> carFeePayStateUpdate(Integer id){
        Result<List<ParkingCarFeeAU>> r=Result.success();
        try {
            this.parkingFeeService.carFeePayStateUpdate(id);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("停车缴费管理 删除")
    @DeleteMapping("/carFee/delete")
    public Result<List<ParkingCarFeeAU>> carFeeDelete(Integer id){
        Result<List<ParkingCarFeeAU>> r=Result.success();
        try {
            this.parkingFeeService.carFeeDelete(id);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("停车缴费管理 批量删除")
    @DeleteMapping("/carFee/ids/delete")
    public Result<List<ParkingCarFeeAU>> carFeeDeleteIds(@RequestBody List<Integer> ids){
        Result<List<ParkingCarFeeAU>> r=Result.success();
        try {
            this.parkingFeeService.carFeeDeleteIds(ids);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

}
